#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
表情包和星号去除功能测试脚本
"""

from comment_processor import CommentProcessor

def test_emoji_and_star_removal():
    """测试表情包和星号去除功能"""
    print("=== 表情包和星号去除功能测试 ===")
    
    processor = CommentProcessor()
    
    # 测试用例
    test_cases = [
        # 基础表情包测试
        ("这个商品很好😀", "这个商品很好"),
        ("质量不错👍", "质量不错"),
        ("包装精美❤️", "包装精美"),
        ("服务很好😊", "服务很好"),
        
        # 星号测试
        ("这个商品***很好", "这个商品很好"),
        ("质量****不错", "质量不错"),
        ("包装*精美*", "包装精美"),
        ("服务**很好**", "服务很好"),
        
        # 特殊符号测试
        ("包装★精美", "包装精美"),
        ("服务☆很好", "服务很好"),
        ("推荐♥购买", "推荐购买"),
        ("质量✩不错", "质量不错"),
        
        # 混合测试
        ("欢潮转珠棒😀***很好用", "很好用"),
        ("在淘宝买的，包装★精美❤️", "在买的，包装精美"),
        ("这个商品*很好*😊", "这个商品很好"),
        ("质量****不错👍", "质量不错"),
        
        # 复杂情况测试
        ("欢潮转珠棒😀😊😍***很好用，，，，", "很好用，"),
        ("在淘宝买的，包装★☆♥精美❤️💖", "在买的，包装精美"),
        ("这个商品*很好*😊😍，值得购买👍", "这个商品很好，值得购买"),
        ("质量****不错👍😊，性价比高💯", "质量不错，性价比高"),
        
        # 边界情况测试
        ("***", ""),
        ("😀😊😍", ""),
        ("*😀*", ""),
        ("", ""),
        ("没有特殊符号的评论", "没有特殊符号的评论"),
    ]
    
    print(f"{'原始文本':<30} {'处理后文本':<30} {'是否匹配':<10}")
    print("-" * 70)
    
    for i, (input_text, expected) in enumerate(test_cases, 1):
        # 只测试表情包和星号去除功能
        result = processor.remove_emojis(input_text)
        is_match = result == expected
        
        print(f"{input_text:<30} {result:<30} {'✓' if is_match else '✗'}")
        
        if not is_match:
            print(f"  期望: {expected}")
    
    print("\n=== 完整处理流程测试 ===")
    
    # 测试完整处理流程
    complex_test_cases = [
        "欢潮转珠棒😀***很好用，，，，",
        "在淘宝买的，包装★精美❤️",
        "这个商品*很好*😊，值得购买👍",
        "质量****不错👍😊，性价比高💯"
    ]
    
    for i, comment in enumerate(complex_test_cases, 1):
        print(f"\n测试 {i}: {comment}")
        
        processed_comment, info = processor.process_comment(comment)
        
        print(f"处理后: {processed_comment}")
        print(f"是否差评: {info['is_negative']}")
        print(f"是否重复: {info['is_duplicate']}")
        print(f"原始长度: {info['original_length']}")
        print(f"处理后长度: {info['processed_length']}")

def test_specific_patterns():
    """测试特定模式"""
    print("\n=== 特定模式测试 ===")
    
    processor = CommentProcessor()
    
    # 测试各种星号模式
    star_patterns = [
        "*",
        "**",
        "***",
        "****",
        "*****",
        "*商品*",
        "商品***",
        "***商品",
        "*商品***",
        "商品*很好*",
        "*商品*很好*",
        "商品*很好*商品"
    ]
    
    print("星号模式测试:")
    for pattern in star_patterns:
        result = processor.remove_emojis(pattern)
        print(f"'{pattern}' -> '{result}'")
    
    # 测试各种表情包模式
    emoji_patterns = [
        "😀",
        "😀😊",
        "😀😊😍",
        "商品😀",
        "😀商品",
        "商品😀商品",
        "😀商品😊",
        "商品😀😊商品"
    ]
    
    print("\n表情包模式测试:")
    for pattern in emoji_patterns:
        result = processor.remove_emojis(pattern)
        print(f"'{pattern}' -> '{result}'")

if __name__ == "__main__":
    test_emoji_and_star_removal()
    test_specific_patterns()
    print("\n测试完成！") 